<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>AP Forest Department R &amp; D Circle</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="description" content="">
		<meta name="author" content="">
		<link rel="shortcut icon" type="image/x-icon" href="images/favicon.png" /> 
		<!-- Le styles -->
		<link href='http://fonts.googleapis.com/css?family=Monda' rel='stylesheet' type='text/css'>
		<link href="css/style.css" rel="stylesheet">
		<link href="css/aptable-responsive.css" rel="stylesheet">		
	</head>
	<body>
	<?php 
	session_start();
	if(isset($_SESSION['issess']) && $_SESSION['issess']!='')
	{
	header("location:admin-page.php");
	}
	?>
		<div class="well">
			<div class="wrapper">
				<div class="logo mar_top">
					<img src="images/apfd-Logo.png"/>
				</div>
				<div>
					<div class="span4">
						<form class="login"  >
						<h1>Log In</h1>
						<div class="inputs ">
							<div id="resetmessage"><?php if( isset($_GET["reset"]) ){ if( $_GET["reset"] == "success" ){ echo "Password changed successfully."; } }?></div>
							<input class="username span3" type="text" id="uname" name="uname" placeholder="Username" autofocus required>   
							<input class="password span3" type="password" id="pwd" name="pwd" placeholder="Password" required>
						</div>
						<div id="actions">
							<input type="button" id="submit" onclick="loginForm()" class="submit" value="Log in"><a href="forgot-password.php" > Forgot your password?</a><span id="reload"></span>
						</div>
						<div class="clear val_red_col"></div>
						<div id="email_required" class="val_red_col"></div>
						<div id="password_required" class="val_red_col"></div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
<script src="js/jquery.min.js"></script> 
<script>
$('#pwd').keypress(function(e){
	if( e.keyCode == 13 ){
		loginForm();	
	}
});
function loginForm(){
	var flag=true;
	var uname=$('#uname').val();
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(uname==""){
		  $('#email_required').html('*User email is required');
		  flag=false;
		}else if(!filter.test(uname)){
		  $('#email_required').html('Email format is not correct');
		  flag=false;
		}else{
		 $('#email_required').html('');
		}
	var pwd=$('#pwd').val();
	if(pwd==""){
		  $('#password_required').html('*Password is required');
		  flag=false;
	}else {
		$('#password_required').html('');
	}
	if(flag==false){
		return false;
	}	
	$.ajax({
				type: "POST",
				url: "usernamefind.php",
				data: {uname:uname,pwd:pwd},
				success: function(msg){
					if(msg==1){
						window.location='admin-page.php';
					}
					else{			
						$('.clear').html("Entered userName and  password are worng");
						return false;
					}			
				}
			});	
}
function sendFgtEmail()
    {
		$('#reload').html('<img src="images/ajax-loader.gif"/>');
        $.ajax({
                url:"reset.php",
                success: function(data){
				$('#reload').html('');
                if(data="success")
                {
                    alert("An email has been sent to your register email.Please follow email to reset your password");
                }
                }
            });
    }
</script>